//引入
const filelist = require('../data/filedata')

// 获取列表
const getfiledata = async (req, res) => {
  let result = await filelist.getfiledatalist()
  res.json({
    result
  })
}
//写入
const writeData = (req, res) => {
  const { name, age } = req.body;
  const data = `${name},${age}\n`;
  const filePath = path.join(__dirname, '../data.txt');

  fs.appendFile(filePath, data, (err) => {
    if (err) {
      console.error(err);
      res.status(500).send('错误');
    } else {
      res.status(200).send('写入成功');
    }
  });
};
module.exports = {
  getfiledata,
  writeData
}